<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">

    <title>绑定警员信息</title>
    <link rel="stylesheet" href="//res.wx.qq.com/open/libs/weui/1.0.2/weui.min.css"/>
    <style>
        .page__hd{
            padding:8px;
        }
        .page__title{
            color: #333333;
        }
        .page__desc{
            color: #666666;
        }
    </style>

    <script src="http://api.map.baidu.com/api?v=2.0&ak=BIMkrVrXh34doklbzbUpxEpZvb7zNOtS"
            type="text/javascript"></script>
</head>
<body style="background-color: #F8F8F8">
<div class="page">

    <div class="page__hd">
        <h3 class="page__title">绑定警员信息</h3>
        <p class="page__desc">请准确填写相关信息</p>
    </div>
    <div class="page__bd">

        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                <div class="weui-cell__bd">
                    <input id="input_name" class="weui-input" type="text" placeholder="请输入姓名"/>
                </div>
            </div>
            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd">
                    <label for="" class="weui-label">单位</label>
                </div>
                <div class="weui-cell__bd">
                    <select id="select_department" class="weui-select" name="select2">
                        <option value="">请选择</option>
                        <?php foreach ($depts as $dept): ?>
                        <option value="<?=$dept["name"]?>"><?=$dept["name"]?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">身份证号</label>
                </div>
                <div class="weui-cell__bd">
                    <input id="input_idcard" class="weui-input" type="text" placeholder="请输入身份证号">
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">电话号码</label>
                </div>
                <div class="weui-cell__bd">
                    <input id="input_phone" class="weui-input" type="text" placeholder="请输入电话号码">
                </div>
            </div>

        </div>
        <div class="weui-cells__tips">
            <input id="input_openid" type="hidden" value="<?php echo $openid; ?>">
            <p style="color: #F00;"><?php if (!is_null($user) && $user->checked == 0) {
                    echo '绑定信息审核中，请联系中队后台管理员';
                } ?></p>
        </div>
        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" href="javascript:" id="submit">确定</a>
        </div>
    </div>
</body>

<script src="/static/js/js.cookie.js"></script>
<script src="/static/js/IDValidator.min.js"></script>
<script src="http://cdn.staticfile.org/jquery/2.1.0/jquery.js"></script>
<script>
    $("#input_name").val('<?php if (!is_null($user)) echo $user->name ?>');
    $("#select_department").val('<?php if (!is_null($user)) echo $user->department ?>');
    $("#input_idcard").val('<?php if (!is_null($user)) echo $user->idcard ?>');
    $("#input_phone").val('<?php if (!is_null($user)) echo $user->phone ?>');
    $("#input_openid").val('<?php echo $openid ?>');


    var validator = new IDValidator();

    $("#submit").click(function () {
        var name = $("#input_name").val();
        var department = $("#select_department").val();
        var idcard = $("#input_idcard").val();
        var phone = $("#input_phone").val();
        var openid = $("#input_openid").val();

        if (name.length == 0 || department.length == 0 || idcard.length == 0) {
            alert("请填写完整信息");
        }
        else if (!validator.isValid(idcard)) {
            alert("请填写正确的身份证号");
        }
        else {
            $.post("/wx/register",
                {name: name, department: department, idcard: idcard, openid: openid,phone:phone},
                function (data) {
                    if (data["code"] == 200) {
                        if (data["data"] > 0) {
                            window.location.href = "/wx/sgcl";
                        }
                        else {
                            alert("绑定信息已提交，待审核");
                        }
                    }
                }
            );
        }

    });

</script>
</html>